import { Injectable } from '@nestjs/common';
import { RedisCacheService } from 'src/redis/redis-cache.service';
import { ToolsService } from 'src/utils/tools.service';

@Injectable()
export class CommonService {
  constructor(
    private readonly toolsService: ToolsService,
    private redisCacheService: RedisCacheService,
  ) {}

  async getcaptcha(data): Promise<any> {
    const { id } = data;
    const svgCaptcha = await this.toolsService.captche(); //创建验证码

    this.redisCacheService.cacheSet(
      `captcha_${id}`,
      JSON.stringify(svgCaptcha.text),
      60,
    );

    const cacheData = await this.redisCacheService.cacheGet(`captcha_${id}`);
    console.log(cacheData, 'cacheData');
    // res.type('image/svg+xml'); //指定返回的类型
    return svgCaptcha.data;
  }
}
